#include <string.h>
#include <stdio.h>
#include "sm4.h"

int main(int argc, char** argv)
{
    unsigned char key[16] = {0x20, 0x18, 0x12, 0x34, 0xdf, 0x57, 0x03, 0x12, 0x98, 0xe8, 0x66, 0x57, 0x67, 0xe2, 0x69, 0x7e};
    unsigned char input[16] = {0x20, 0x18, 0x13, 0x34};
    unsigned char output[16];
    sm4_context ctx;
    unsigned long i;
    //key
    printf("key:");
    for(i=0; i<16; i++)
    {
        printf("%02x ",key[i]);
    }
    printf("\n");

    //encrypt
    sm4_setkey_enc(&ctx, key);
    sm4_crypt_ecb(&ctx, 1, 16, input, output);
    printf("encrypt:");
    for (i = 0; i < 16; i++)
        printf("%02x ", output[i]);
    printf("\n");

    //decrypt
    sm4_setkey_dec(&ctx, key);
    sm4_crypt_ecb(&ctx, 0, 16, output, output);
    printf("decrypt:");
    for (i = 0; i < 16; i++)
        printf("%02x ", output[i]);
    printf("\n");
    return 0;
}
